package io.github.bffcorreia.fole;

import android.widget.TextView;

class MaxLinesStateHandler
        implements TextViewStateHandler
{
    private final TextView textView;
    private final String ellipsisPlaceholder;
    private final int maxLines;

    MaxLinesStateHandler(TextView textView, String ellipsisPlaceholder, int maxLines)
    {
        this.textView = textView;
        this.ellipsisPlaceholder = ellipsisPlaceholder;
        this.maxLines = maxLines;
    }

    public boolean isTextExpanded()
    {
        return this.textView.getLineCount() > this.maxLines;
    }

    public String ellipsizedText()
    {
        int lineEndIndex = this.textView.getLayout().getLineEnd(this.maxLines - 1);
        return this.textView.getText().subSequence(0, lineEndIndex - this.ellipsisPlaceholder.length()) + this.ellipsisPlaceholder;
    }
}
